<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Box2D: b2DynamicTree Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="icon.gif"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Box2D
   &#160;<span id="projectnumber">2.2.1</span>
   </div>
   <div id="projectbrief">A 2D Physics Engine for Games</div>
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">b2DynamicTree Class Reference</div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="b2DynamicTree" -->
<p><code>#include &lt;<a class="el" href="b2_dynamic_tree_8h_source.html">b2DynamicTree.h</a>&gt;</code></p>

<p><a href="classb2_dynamic_tree-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a8af64cf6a1566fa4c5b5c9683bd937d9"></a><!-- doxytag: member="b2DynamicTree::b2DynamicTree" ref="a8af64cf6a1566fa4c5b5c9683bd937d9" args="()" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#a8af64cf6a1566fa4c5b5c9683bd937d9">b2DynamicTree</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Constructing the tree initializes the node pool. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a9060565fc63b4dd87d9560775c076786"></a><!-- doxytag: member="b2DynamicTree::~b2DynamicTree" ref="a9060565fc63b4dd87d9560775c076786" args="()" -->
&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#a9060565fc63b4dd87d9560775c076786">~b2DynamicTree</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Destroy the tree, freeing the node pool. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ae44676f12977dada46037da47fc7ffbf"></a><!-- doxytag: member="b2DynamicTree::CreateProxy" ref="ae44676f12977dada46037da47fc7ffbf" args="(const b2AABB &amp;aabb, void *userData)" -->
int32&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#ae44676f12977dada46037da47fc7ffbf">CreateProxy</a> (const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;aabb, void *userData)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Create a proxy. Provide a tight fitting AABB and a userData pointer. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a62aa451e7d7fe029818dd05f76ea9cdc"></a><!-- doxytag: member="b2DynamicTree::DestroyProxy" ref="a62aa451e7d7fe029818dd05f76ea9cdc" args="(int32 proxyId)" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#a62aa451e7d7fe029818dd05f76ea9cdc">DestroyProxy</a> (int32 proxyId)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Destroy a proxy. This asserts if the id is invalid. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#a7748252811f3c575015931399cbe4daa">MoveProxy</a> (int32 proxyId, const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;aabb1, const <a class="el" href="structb2_vec2.html">b2Vec2</a> &amp;displacement)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#a44ab57dce3c42b0a5847a64e489a71ce">GetUserData</a> (int32 proxyId) const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="adf4676b1c34a57b4451bcbeaebe65687"></a><!-- doxytag: member="b2DynamicTree::GetFatAABB" ref="adf4676b1c34a57b4451bcbeaebe65687" args="(int32 proxyId) const " -->
const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#adf4676b1c34a57b4451bcbeaebe65687">GetFatAABB</a> (int32 proxyId) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the fat AABB for a proxy. <br/></td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;typename T &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#adf70aee89b4692fc79d65b1f54308585">Query</a> (T *callback, const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;aabb) const </td></tr>
<tr><td class="memTemplParams" colspan="2">template&lt;typename T &gt; </td></tr>
<tr><td class="memTemplItemLeft" align="right" valign="top">void&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#abd7a5c6a5bc109dbbdb0ec3aae039648">RayCast</a> (T *callback, const <a class="el" href="structb2_ray_cast_input.html">b2RayCastInput</a> &amp;input) const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="abfac96c615b08406cba3e53b39800f1c"></a><!-- doxytag: member="b2DynamicTree::Validate" ref="abfac96c615b08406cba3e53b39800f1c" args="() const " -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#abfac96c615b08406cba3e53b39800f1c">Validate</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Validate this tree. For testing. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#add7e09cdf279e7c0031da9dfd4cdf4db">GetHeight</a> () const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top">int32&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#ae02c45d1a68b42e59d170438ddbb7977">GetMaxBalance</a> () const </td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ad78282a720c451e032b43c34cba02f1a"></a><!-- doxytag: member="b2DynamicTree::GetAreaRatio" ref="ad78282a720c451e032b43c34cba02f1a" args="() const " -->
float32&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#ad78282a720c451e032b43c34cba02f1a">GetAreaRatio</a> () const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the ratio of the sum of the node areas to the root area. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="abd146017cfec1cf5ea7b87331f30a3ff"></a><!-- doxytag: member="b2DynamicTree::RebuildBottomUp" ref="abd146017cfec1cf5ea7b87331f30a3ff" args="()" -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="classb2_dynamic_tree.html#abd146017cfec1cf5ea7b87331f30a3ff">RebuildBottomUp</a> ()</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Build an optimal tree. Very expensive. For testing. <br/></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>A dynamic AABB tree broad-phase, inspired by Nathanael Presson's btDbvt. A dynamic tree arranges data in a binary tree to accelerate queries such as volume queries and ray casts. Leafs are proxies with an AABB. In the tree we expand the proxy AABB by b2_fatAABBFactor so that the proxy AABB is bigger than the client object. This allows the client object to move by small amounts without triggering a tree update.</p>
<p>Nodes are pooled and relocatable, so we use node indices rather than pointers. </p>
</div><hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="add7e09cdf279e7c0031da9dfd4cdf4db"></a><!-- doxytag: member="b2DynamicTree::GetHeight" ref="add7e09cdf279e7c0031da9dfd4cdf4db" args="() const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32 b2DynamicTree::GetHeight </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Compute the height of the binary tree in O(N) time. Should not be called often. </p>

</div>
</div>
<a class="anchor" id="ae02c45d1a68b42e59d170438ddbb7977"></a><!-- doxytag: member="b2DynamicTree::GetMaxBalance" ref="ae02c45d1a68b42e59d170438ddbb7977" args="() const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32 b2DynamicTree::GetMaxBalance </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td> const</td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Get the maximum balance of an node in the tree. The balance is the difference in height of the two children of a node. </p>

</div>
</div>
<a class="anchor" id="a44ab57dce3c42b0a5847a64e489a71ce"></a><!-- doxytag: member="b2DynamicTree::GetUserData" ref="a44ab57dce3c42b0a5847a64e489a71ce" args="(int32 proxyId) const " -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void * b2DynamicTree::GetUserData </td>
          <td>(</td>
          <td class="paramtype">int32&#160;</td>
          <td class="paramname"><em>proxyId</em></td><td>)</td>
          <td> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Get proxy user data. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>the proxy user data or 0 if the id is invalid. </dd></dl>

</div>
</div>
<a class="anchor" id="a7748252811f3c575015931399cbe4daa"></a><!-- doxytag: member="b2DynamicTree::MoveProxy" ref="a7748252811f3c575015931399cbe4daa" args="(int32 proxyId, const b2AABB &amp;aabb1, const b2Vec2 &amp;displacement)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool b2DynamicTree::MoveProxy </td>
          <td>(</td>
          <td class="paramtype">int32&#160;</td>
          <td class="paramname"><em>proxyId</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;&#160;</td>
          <td class="paramname"><em>aabb1</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structb2_vec2.html">b2Vec2</a> &amp;&#160;</td>
          <td class="paramname"><em>displacement</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, then the proxy is removed from the tree and re-inserted. Otherwise the function returns immediately. </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>true if the proxy was re-inserted. </dd></dl>

</div>
</div>
<a class="anchor" id="adf70aee89b4692fc79d65b1f54308585"></a><!-- doxytag: member="b2DynamicTree::Query" ref="adf70aee89b4692fc79d65b1f54308585" args="(T *callback, const b2AABB &amp;aabb) const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void b2DynamicTree::Query </td>
          <td>(</td>
          <td class="paramtype">T *&#160;</td>
          <td class="paramname"><em>callback</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structb2_a_a_b_b.html">b2AABB</a> &amp;&#160;</td>
          <td class="paramname"><em>aabb</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Query an AABB for overlapping proxies. The callback class is called for each proxy that overlaps the supplied AABB. </p>

</div>
</div>
<a class="anchor" id="abd7a5c6a5bc109dbbdb0ec3aae039648"></a><!-- doxytag: member="b2DynamicTree::RayCast" ref="abd7a5c6a5bc109dbbdb0ec3aae039648" args="(T *callback, const b2RayCastInput &amp;input) const " -->
<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename T &gt; </div>
      <table class="memname">
        <tr>
          <td class="memname">void b2DynamicTree::RayCast </td>
          <td>(</td>
          <td class="paramtype">T *&#160;</td>
          <td class="paramname"><em>callback</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const <a class="el" href="structb2_ray_cast_input.html">b2RayCastInput</a> &amp;&#160;</td>
          <td class="paramname"><em>input</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td> const<code> [inline]</code></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>Ray-cast against the proxies in the tree. This relies on the callback to perform a exact ray-cast in the case were the proxy contains a shape. The callback also performs the any collision filtering. This has performance roughly equal to k * log(n), where k is the number of collisions and n is the number of proxies in the tree. </p>
<dl><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">input</td><td>the ray-cast input data. The ray extends from p1 to p1 + maxFraction * (p2 - p1). </td></tr>
    <tr><td class="paramname">callback</td><td>a callback class that is called for each proxy that is hit by the ray. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="b2_dynamic_tree_8h_source.html">b2DynamicTree.h</a></li>
<li>b2DynamicTree.cpp</li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Sep 17 2011 17:35:55 for Box2D by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
